package com.sherlochao.dao.impl;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.sherlochao.dao.ShareTalkDao;
import com.sherlochao.model.ShareTalk;

@Repository("shareTalkDao")
public class ShareTalkDaoImpl implements ShareTalkDao{
	
	@Resource
	private SessionFactory sessionFactory;
		
	public Session getSession() {
		//return sessionFactory.openSession();
		return sessionFactory.getCurrentSession();
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public ShareTalk get(String id) {
		String hql = "from ShareTalk where id = ?";
		Query query = this.getSession().createQuery(hql);
		query.setString(0, id);
		return (ShareTalk)query.uniqueResult();
	}

	@Override
	public String save(ShareTalk entity) {
		return (String)this.getSession().save(entity);
	}

	@Override
	public void delete(String id) {
		ShareTalk entity = this.load(id);
		this.getSession().delete(entity);
		
	}

	@Override
	public ShareTalk load(String id) {
		return (ShareTalk)this.getSession().load(ShareTalk.class,id);
	}

	@Override
	public void update(String shareTalkContent, String userId) {
		
	}

}
